package com.anjho.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Query;

import com.anjho.pojo.Address;

public class DAOAddress extends DAOGeneric implements Serializable {

	private static final long serialVersionUID = 6522206391994327208L;
	
	public DAOAddress() {
		super();
	}

	@SuppressWarnings("unchecked")
	public List<Address> getAddressList() throws Exception {
		return (List<Address>)super.getList("Address.getAddressList");
	}
	
	@SuppressWarnings("unchecked")
	public List<Address> getAddressListByZip(String zip) {
		Query query = entityManager.createNamedQuery("Address.getAddressListByZip");
		query.setParameter("zip", zip);
		System.out.println(query.toString());
		List<Address> addresses = null;
		try {
			addresses = query.getResultList();
		} catch (Exception e){
			//TODO: TRATAMENTO DE ERROS
			e.printStackTrace();
		}
		return addresses;
	}
	
	public Address getAddressByAdCode(Long adcode) {
		Query query = entityManager.createNamedQuery("Address.getAddressByAdCode");
		query.setParameter("adcode", adcode);
		System.out.println(query.toString());
		Address address = null;
		try {
			address = (Address)query.getSingleResult();
		} catch (Exception e){
			//TODO: TRATAMENTO DE ERROS
			e.printStackTrace();
		}
		return address;
	}

}
